package com.easyskool.composer;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.json.JSONException;
import org.json.JSONObject;

import com.easyskool.constants.CommonConstants;
import com.easyskool.constants.EmailLinkConstants;
import com.easyskool.constants.TableNames;
import com.easyskool.dao.BaseDao;
import com.easyskool.exception.ComposerException;
import com.easyskool.exception.DaoException;
import com.easyskool.hibernate.model.Classes;
import com.easyskool.hibernate.model.ContactForms;
import com.easyskool.hibernate.model.FollowupDetails;
import com.easyskool.hibernate.model.Sections;
import com.easyskool.util.mailUtil;
import com.easyskool.utilfunction.NullObjects;
import com.easyskool.utilfunction.UtilFunctions;
import com.ivp.cloud.stratus.logger.LoggingUtil;

@SuppressWarnings({ "unchecked", "rawtypes" })
public class WebadminComposer {

	BaseDao baseDao;

	/**
	 * Logger
	 */
	private static LoggingUtil logger = (LoggingUtil) LoggingUtil
			.getLogger(WebadminComposer.class.getName());

	/**
	 * Object for BaseDao
	 * 
	 * @return
	 */
	public BaseDao getBaseDao() {
		if (NullObjects.isNull(baseDao)) {
			baseDao = new BaseDao();
		}
		return baseDao;
	}

	/**
	 * 
	 * @param user
	 * @param toInsert
	 * @return String
	 * @throws IOException
	 * @throws IllegalAccessException
	 * @throws InstantiationException
	 * @throws JsonMappingException
	 * @throws JsonParseException
	 * @throws JSONException
	 * @throws Exception
	 */
	public void insertfollowUpDetails(String user,String dataString)
			throws ComposerException, JSONException {
		System.out.println("Data entering insertfollowupdetails composer "+user+" "+dataString);
		try {
			JSONObject json = new JSONObject(dataString);
			
			ContactForms cf = new ContactForms();
			cf.setRowId(json.getLong("contacts"));
			FollowupDetails fd= new FollowupDetails();
			fd.setContactForms(cf);
			fd.setCreatedDate(new Date());
			fd.setModifiedDate(new Date());
			fd.setFdFollowupDate(new Date());
			fd.setFdContactCode(user); 
			fd.setFdLog(json.getString("fdLog"));
			fd.setCreatedBy(user);
			fd.setModifiedBy(user);
			fd.setUaCode(json.getString("uaCode"));
//			toInsert = UtilFunctions.insertParamAdd(user, toInsert);
			getBaseDao().insertWithObject(FollowupDetails.class, fd);
			logger.info("exiting createMasterSection");
		} catch (DaoException e) {
			logger.error(e + ":" + e.getErrorMsg() + ":"
					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());

			ComposerException d = new ComposerException(e.getErrorMsg(), e);
			throw d;
		} catch (Exception e) {
			logger.error(e + e.getMessage() + ":" + e.getCause());

			ComposerException d = new ComposerException(e.getMessage(), e);
			throw d;
		}
		return;
	}
//	/**
//	 * 
//	 * @param user
//	 * @param toInsert
//	 * @return String
//	 * @throws IOException
//	 * @throws IllegalAccessException
//	 * @throws InstantiationException
//	 * @throws JsonMappingException
//	 * @throws JsonParseException
//	 * @throws JSONException
//	 * @throws Exception
//	 */
//	public void createMasterSection(String user, String toInsert)
//			throws ComposerException, JSONException {
//		try {
//			toInsert = UtilFunctions.insertParamAdd(user, toInsert);
//			getBaseDao().insert(TableNames.wSection, toInsert);
//			logger.info("exiting createMasterSection");
//		} catch (DaoException e) {
//			logger.error(e + ":" + e.getErrorMsg() + ":"
//					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());
//
//			ComposerException d = new ComposerException(e.getErrorMsg(), e);
//			throw d;
//		} catch (Exception e) {
//			logger.error(e + e.getMessage() + ":" + e.getCause());
//
//			ComposerException d = new ComposerException(e.getMessage(), e);
//			throw d;
//		}
//		return;
//	}
//
	/**
	 * 
	 * @param user
	 * @param whereClause
	 * @return String
	 * @throws ComposerException
	 * @throws Exception
	 */
	public String getMasterSection(String user, String whereClause)
			throws DaoException, ComposerException {
		String str = null;
		try {
			ObjectMapper mapper = new ObjectMapper();
			Map whereMap = mapper.readValue(whereClause, HashMap.class);

			List<Sections> wSections = getBaseDao().find(TableNames.masterSection,
					whereMap);

			str = mapper.writeValueAsString(wSections);
		} catch (DaoException e) {
			logger.error(e + ":" + e.getErrorMsg() + ":"
					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());

			ComposerException d = new ComposerException(e.getErrorMsg(), e);
			throw d;
		} catch (Exception e) {
			logger.error(e + e.getMessage() + ":" + e.getCause());

			ComposerException d = new ComposerException(e.getMessage(), e);
			throw d;
		}

		logger.info("exiting getMasterSection");
		return str;
	}

	/**
	 * 
	 * @param user
	 * @param whereClause
	 * @param updateClause
	 * @return String
	 * @throws Exception
	 */
	public void updateMasterSection(String user, String whereClause,
			String updateClause) throws Exception {
		try {
			ObjectMapper mapper = new ObjectMapper();
			Map whereMap = mapper.readValue(whereClause, HashMap.class);

			updateClause = UtilFunctions.updateParamAdd(user, updateClause);

			getBaseDao().update(TableNames.masterSection, whereMap, updateClause);
		} catch (DaoException e) {
			logger.error(e + ":" + e.getErrorMsg() + ":"
					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());

			ComposerException d = new ComposerException(e.getErrorMsg(), e);
			throw d;
		} catch (Exception e) {
			logger.error(e + e.getMessage() + ":" + e.getCause());

			ComposerException d = new ComposerException(e.getMessage(), e);
			throw d;
		}
		logger.info("exiting updateMasterSection");
		return;
	}

	/**
	 * 
	 * @param user
	 * @param whereClause
	 * @return String
	 * @throws Exception
	 */
	public void deleteMasterSection(String user, String whereClause)
			throws Exception {
		try {
			ObjectMapper mapper = new ObjectMapper();
			Map<String, Object> whereMap = mapper.readValue(whereClause,
					HashMap.class);

			getBaseDao().deleteWithoutFullObject(TableNames.masterSection, whereMap);
		} catch (DaoException e) {
			logger.error(e + ":" + e.getErrorMsg() + ":"
					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());

			ComposerException d = new ComposerException(e.getErrorMsg(), e);
			throw d;
		} catch (Exception e) {
			logger.error(e + e.getMessage() + ":" + e.getCause());

			ComposerException d = new ComposerException(e.getMessage(), e);
			throw d;
		}
		logger.info("exiting deleteMasterSection");
		return;
	}

	/**
	 * 
	 * @param user
	 * @param whereClause
	 * @return String
	 * @throws Exception
	 */
	public void deleteSelectedMasterSection(String user, String whereClause)
			throws Exception {
		try {
			ObjectMapper mapper = new ObjectMapper();
			Map<String, Object> whereMap = mapper.readValue(whereClause,
					HashMap.class);

			getBaseDao().batchDelete(TableNames.masterSection, whereMap);
		} catch (DaoException e) {
			logger.error(e + ":" + e.getErrorMsg() + ":"
					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());

			ComposerException d = new ComposerException(e.getErrorMsg(), e);
			throw d;
		} catch (Exception e) {
			logger.error(e + e.getMessage() + ":" + e.getCause());

			ComposerException d = new ComposerException(e.getMessage(), e);
			throw d;
		}
		logger.info("exiting deleteSelectedMasterSection");
		return;
	}

	public void createMasterClass(String user, String toInsert)
			throws Exception {
		try {
			toInsert = UtilFunctions.insertParamAdd(user, toInsert);
			getBaseDao().insert(TableNames.masterClass, toInsert);
			logger.info("exiting createMasterClass");
		} catch (DaoException e) {
			logger.error(e + ":" + e.getErrorMsg() + ":"
					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());

			ComposerException d = new ComposerException(e.getErrorMsg(), e);
			throw d;
		} catch (Exception e) {
			logger.error(e + e.getMessage() + ":" + e.getCause());

			ComposerException d = new ComposerException(e.getMessage(), e);
			throw d;
		}
		logger.info("exiting deleteSelectedMasterSection");
		return;
	}

	// --------------------------------------------------------------------------------------------------

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public String getMasterClass(String whereClause)
			throws Exception {

		ObjectMapper mapper = new ObjectMapper();
		String str = null;
		Map whereMap = null;
		try {
			if(!NullObjects.isNull(whereClause)){
				whereMap = mapper.readValue(whereClause, HashMap.class);
			}
			List<Classes> wClasses = getBaseDao().find(TableNames.masterClass,
					whereMap);
//			System.out.println("wclass object : "+wClasses.get(0).getClassDescription());
			if(!NullObjects.isNull(wClasses)){
				str = mapper.writeValueAsString(wClasses);
			}
		} catch (DaoException e) {
			logger.error(e + ":" + e.getErrorMsg() + ":"
					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());

			ComposerException d = new ComposerException(e.getErrorMsg(), e);
			throw d;
		} catch (Exception e) {
			logger.error(e + e.getMessage() + ":" + e.getCause());
e.printStackTrace();
			ComposerException d = new ComposerException(e.getMessage(), e);
			throw d;
		}
		logger.info("exiting getMasterClass");

		return str;
	}

	// --------------------------------------------------------------------------------------------------

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void updateMasterClass(String whereClause,
			String updateClause) throws Exception {

		ObjectMapper mapper = new ObjectMapper();
		try {
//			updateClause = UtilFunctions.updateParamAdd(user, updateClause);
			Map whereMap = mapper.readValue(whereClause, HashMap.class);
			updateClause=	UtilFunctions.updateParamAdd("admin", updateClause);
			getBaseDao().update(TableNames.masterClass, whereMap, updateClause);
			logger.info("exiting updateMasterClass");
		} catch (DaoException e) {
			logger.error(e + ":" + e.getErrorMsg() + ":"
					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());

			ComposerException d = new ComposerException(e.getErrorMsg(), e);
			throw d;
		} catch (Exception e) {
			logger.error(e + e.getMessage() + ":" + e.getCause());
e.printStackTrace();
			ComposerException d = new ComposerException(e.getMessage(), e);
			throw d;
		}
	}

	// --------------------------------------------------------------------------------------------------
	
	public void deleteMasterClass(String user, String whereClause)
			throws Exception {

		try {
			ObjectMapper mapper = new ObjectMapper();
			Map<String, Object> whereMap = mapper.readValue(whereClause,
					HashMap.class);
System.out.println("here : ");
			getBaseDao().deleteWithoutFullObject(TableNames.masterClass, whereMap);
			logger.info("exiting deleteMasterClass");
		} catch (DaoException e) {
			logger.error(e + ":" + e.getErrorMsg() + ":"
					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());

			ComposerException d = new ComposerException(e.getErrorMsg(), e);
			throw d;
		} catch (Exception e) {
			logger.error(e + e.getMessage() + ":" + e.getCause());

			ComposerException d = new ComposerException(e.getMessage(), e);
			throw d;
		}

	}

	// --------------------------------------------------------------------------------------------------
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void deleteSelectedMasterClass(String user, String whereClause)
			throws Exception {

		ObjectMapper mapper = new ObjectMapper();
		try {
		
				Map<String, Object> whereMap = mapper.readValue(whereClause,
						HashMap.class);

				getBaseDao().batchDelete(TableNames.masterClass, whereMap);
				
			logger.info("exiting deleteSelectedMasterSection");
		} catch (DaoException e) {
			logger.error(e + ":" + e.getErrorMsg() + ":"
					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());

			ComposerException d = new ComposerException(e.getErrorMsg(), e);
			throw d;
		} catch (Exception e) {
			logger.error(e + e.getMessage() + ":" + e.getCause());

			ComposerException d = new ComposerException(e.getMessage(), e);
			throw d;
		}
	}

//	
//	public void createMasterSubject(String user, String toInsert)
//			throws ComposerException, JSONException {
//		try {
//			toInsert = UtilFunctions.insertParamAdd(user, toInsert);
//			getBaseDao().insert(TableNames.wSubject, toInsert);
//			logger.info("exiting createMasterSubject");
//		} catch (DaoException e) {
//			logger.error(e + ":" + e.getErrorMsg() + ":"
//					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());
//
//			ComposerException d = new ComposerException(e.getErrorMsg(), e);
//			throw d;
//		} catch (Exception e) {
//			logger.error(e + e.getMessage() + ":" + e.getCause());
//
//			ComposerException d = new ComposerException(e.getMessage(), e);
//			throw d;
//		}
//		return;
//	}
//
//	/**
//	 * 
//	 * @param user
//	 * @param whereClause
//	 * @return String
//	 * @throws ComposerException
//	 * @throws Exception
//	 */
//	public String getMasterSubject(String user, String whereClause)
//			throws DaoException, ComposerException {
//		String str = null;
//		try {
//			ObjectMapper mapper = new ObjectMapper();
//			Map whereMap = mapper.readValue(whereClause, HashMap.class);
//
//			List<WSubject> wSubjects = getBaseDao().find(TableNames.wSubject,
//					whereMap);
//
//			str = mapper.writeValueAsString(wSubjects);
//		} catch (DaoException e) {
//			logger.error(e + ":" + e.getErrorMsg() + ":"
//					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());
//
//			ComposerException d = new ComposerException(e.getErrorMsg(), e);
//			throw d;
//		} catch (Exception e) {
//			logger.error(e + e.getMessage() + ":" + e.getCause());
//
//			ComposerException d = new ComposerException(e.getMessage(), e);
//			throw d;
//		}
//
//		logger.info("exiting getMasterSubject");
//		return str;
//	}
//
//	/**
//	 * 
//	 * @param user
//	 * @param whereClause
//	 * @param updateClause
//	 * @return String
//	 * @throws Exception
//	 */
//	public void updateMasterSubject(String user, String whereClause,
//			String updateClause) throws Exception {
//		try {
//			ObjectMapper mapper = new ObjectMapper();
//			Map whereMap = mapper.readValue(whereClause, HashMap.class);
//
//			updateClause = UtilFunctions.updateParamAdd(user, updateClause);
//
//			getBaseDao().update(TableNames.wSubject, whereMap, updateClause);
//		} catch (DaoException e) {
//			logger.error(e + ":" + e.getErrorMsg() + ":"
//					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());
//
//			ComposerException d = new ComposerException(e.getErrorMsg(), e);
//			throw d;
//		} catch (Exception e) {
//			logger.error(e + e.getMessage() + ":" + e.getCause());
//
//			ComposerException d = new ComposerException(e.getMessage(), e);
//			throw d;
//		}
//		logger.info("exiting updateMasterSubject");
//		return;
//	}
//
//	/**
//	 * 
//	 * @param user
//	 * @param whereClause
//	 * @return String
//	 * @throws Exception
//	 */
//	public void deleteMasterSubject(String user, String whereClause)
//			throws Exception {
//		try {
//			ObjectMapper mapper = new ObjectMapper();
//			Map<String, Object> whereMap = mapper.readValue(whereClause,
//					HashMap.class);
//
//			getBaseDao().deleteWithoutFullObject(TableNames.wSubject, whereMap);
//		} catch (DaoException e) {
//			logger.error(e + ":" + e.getErrorMsg() + ":"
//					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());
//
//			ComposerException d = new ComposerException(e.getErrorMsg(), e);
//			throw d;
//		} catch (Exception e) {
//			logger.error(e + e.getMessage() + ":" + e.getCause());
//
//			ComposerException d = new ComposerException(e.getMessage(), e);
//			throw d;
//		}
//		logger.info("exiting deleteMasterSubject");
//		return;
//	}
//	public void deleteSelectedMasterSubject(String user, String whereClause)
//			throws Exception {
//
//		ObjectMapper mapper = new ObjectMapper();
//		try {
//		
//				Map<String, Object> whereMap = mapper.readValue(whereClause,
//						HashMap.class);
//
//				getBaseDao().batchDelete(TableNames.wSubject, whereMap);
//				
//			logger.info("exiting deleteSelectedMasterSection");
//		} catch (DaoException e) {
//			logger.error(e + ":" + e.getErrorMsg() + ":"
//					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());
//
//			ComposerException d = new ComposerException(e.getErrorMsg(), e);
//			throw d;
//		} catch (Exception e) {
//			logger.error(e + e.getMessage() + ":" + e.getCause());
//
//			ComposerException d = new ComposerException(e.getMessage(), e);
//			throw d;
//		}
//	}
//
//	public String getSchoolRequests(String user, String whereClause)
//			throws ComposerException {
//		logger.info("Entering getSchoolRequests");
//		String str = null;
//		try {
//			ObjectMapper mapper = new ObjectMapper();
//			Map whereMap = new HashMap<String, Object>();
//			whereMap.put("requestStatus", 0);
//			List<SchoolRequest> schoolRequests = getBaseDao().find(
//					SchoolRequest.class, whereMap);
//
//			str = mapper.writeValueAsString(schoolRequests);
//		} catch (DaoException e) {
//			logger.error(e + ":" + e.getErrorMsg() + ":"
//					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());
//
//			ComposerException d = new ComposerException(e.getErrorMsg(), e);
//			throw d;
//		} catch (Exception e) {
//			logger.error(e + e.getMessage() + ":" + e.getCause());
//
//			ComposerException d = new ComposerException(e.getMessage(), e);
//			throw d;
//		}
//
//		logger.info("exiting getSchoolRequests");
//		return str;
//	}
//
//	public String rejectSchoolRequest(String user, String whereClause)
//			throws ComposerException {
//		try {
//			ObjectMapper mapper = new ObjectMapper();
//			Map whereMap = new HashMap<String, Object>();// mapper.readValue(whereClause,
//															// HashMap.class);
//			JSONObject jsonObj = new JSONObject(whereClause);
//			int code = (jsonObj.getInt("schoolCode"));
//			logger.info("School Code: " + code);
//			String admEmail=jsonObj.getString("admEmail");
//			whereMap.put("schoolCode", code);
//			logger.info("Rejecting school: "+code);
//			// int code=Integer.parseInt( (String) whereMap.get("schoolCode"));
//			// whereMap.get("schoolCode") =code;
//			Map<String, Object> updateClause = new HashMap<String, Object>();
//			updateClause.put("requestStatus", -1);
//			updateClause.put("requestStatusChangedBy", user);
//			updateClause.put("requestStatusChangedDate", new Date());
//			getBaseDao().updateWithoutFullobject(TableNames.schoolRequest,
//					whereMap, updateClause);
//			System.out.println("Sending the rejection email to "+admEmail);
//			new mailUtil(admEmail, "For Admin @ easyskool.com", "Your School Request has been rejected ");
//		} catch (DaoException e) {
//			logger.error(e + ":" + e.getErrorMsg() + ":"
//					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());
//
//			ComposerException d = new ComposerException(e.getErrorMsg(), e);
//			throw d;
//		} catch (Exception e) {
//			logger.error(e + e.getMessage() + ":" + e.getCause());
//
//			ComposerException d = new ComposerException(e.getMessage(), e);
//			throw d;
//		}
//		logger.info("exiting updateMasterSection");
//		return CommonConstants.SUCCESS;
//	}
///**
// * Adds data to accessAuth, AdmDetails, SchoolDetails and modifies SchooolRequest
// * @param user
// * @param whereClause
// * @return
// * @throws ComposerException
// * @throws DaoException
// */
//	public String acceptSchoolRequest(String user, String whereClause)
//			throws ComposerException, DaoException {
//		int aaCode=0;
//		int adCode=0;
//		int sdCode=0;
//		try {
//			ObjectMapper mapper = new ObjectMapper();
//			Map whereMap = new HashMap<String, Object>();
//			JSONObject jsonObj = new JSONObject(whereClause);
//			int code = (jsonObj.getInt("schoolCode"));
//			int schoolCode=code;
//			System.out.println("Entering AccessAuthorization");
//	        logger.debug("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~AccessAutorization Start~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
//			AccessAuthorization aa =new AccessAuthorization();
//			aa.setAaEmail(jsonObj.getString("admEmail"));
//			aa.setAaMobileNumber(jsonObj.getString("aaMobileNumber"));
//			aa.setAaIsBlocked(1);
//			aa.setAaPriviledgeLevel("Admin");
//			aa.setAaSecurityA1("aaSecurityA1");
//			aa.setAaSecurityA2("aaSecurityA2");
//			aa.setAaSecurityQ1("aaSecurityQ1");
//			aa.setAaSecurityQ2("aaSecurityQ2");			
//			aa.setCreatedBy(user);
//			aa.setCreatedDate(new Date());
//			aa.setAaPassword("realone");
//			aa.setModifiedBy(user);
//			aa.setAaSchoolCode(code);
//			aa.setModifiedDate(new Date());
//			aa.setAaCode(42);
//			System.out.println("BEFORE: "+aa.getAaCode());
//			aa=getBaseDao().insertWithObject(AccessAuthorization.class,aa);
//			System.out.println("AFTER: "+aa.getAaCode());
//			aaCode=aa.getAaCode();
//			System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~AccessAutorization End~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
//			System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~AdminDetails Start~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
//			AdminDetails ad=new AdminDetails();
//			
//			ad.setAaCode(aaCode);
//			ad.setAdmEmail(jsonObj.getString("admEmail"));
//			ad.setAdmFname(jsonObj.getString("admFname"));
//			ad.setAdmMname(jsonObj.getString("admMname"));
//			ad.setAdmLname(jsonObj.getString("admLname"));
//			ad.setAdmCurrentSchool(schoolCode);
//			ad.setCreatedDate(new Date());
//			ad.setModifiedBy(user);
//			ad.setModifiedDate(new Date());
//			ad.setCreatedBy(user);
//			ad=getBaseDao().insertWithObject(AdminDetails.class,ad);
//			adCode=ad.getAaCode();
//			System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~AdminDetails End~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
//			System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SchoolDetails Start~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
//			SchoolDetails sd = new SchoolDetails();
//			sd.setSchoolCode(schoolCode);
//			sd.setScAdminCode(ad.getAaCode());
//			sd.setScAddress(jsonObj.getString("scAddress"));
//			sd.setScAffiliation((jsonObj.getString("scAffliation")));
//			sd.setScCity(jsonObj.getString("scCity"));
//			sd.setScPin(jsonObj.getString("scPin"));
//			sd.setScName((jsonObj.getString("scName")));
//			sd.setScCountry((jsonObj.getString("scCountry")));
//			sd.setScState((jsonObj.getString("scState")));
//			sd.setScAddress(jsonObj.getString("scAddress"));
//			sd.setScNoOfStudents(jsonObj.getInt("scNoOfStudents"));
//			sd.setCreatedBy(user);
//			sd.setCreatedDate(new Date());
//			sd.setModifiedBy(user);
//			sd.setModifiedDate(new Date());
//			sd=getBaseDao().insertWithObject(SchoolDetails.class,sd);	
//			sdCode=sd.getSchoolCode();
//			System.out.println(aaCode+" :Admin Code "+schoolCode+" :SchoolCode "+sdCode+" :School DEtails code");
//			System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SchoolDetails End~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
//			System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SchoolRequest Start~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
//			logger.info("School Code: " + code);
//			whereMap.put("schoolCode", code);
//			// int code=Integer.parseInt( (String) whereMap.get("schoolCode"));
//			// whereMap.get("schoolCode") =code;
//			Map<String, Object> updateClause = new HashMap<String, Object>();
//			updateClause.put("requestStatus", 1);
//			updateClause.put("requestStatusChangedBy", user);
//			updateClause.put("requestStatusChangedDate", new Date());
//			schoolCode=getBaseDao().updateWithoutFullobject(TableNames.schoolRequest,
//					whereMap, updateClause);
//			System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SchoolRequest End~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
//			System.out.println("Sending the email to "+aa.getAaEmail());
//			new mailUtil(aa.getAaEmail(), "For Admin @ easyskool.com", "Your School Request has been approved, " +
//					"Please follow the below link to change the password "+EmailLinkConstants.FIRST_TIME_INFO+"?id="+aaCode+"&type=Admin");
//			
//		} catch (DaoException e) {
//			System.out.println("Entering DAO exception");
//			logger.error(e + ":" + e.getErrorMsg() + ":"
//					+ e.getExthr().getMessage() + ":" + e.getExthr().getCause());
//			Map<String, Object> where=new HashMap<String, Object>();
//			where.put("aaCode", aaCode);
//			getBaseDao().deleteWithoutFullObject(AccessAuthorization.class, where);
//			getBaseDao().deleteWithoutFullObject(AdminDetails.class, where);
//			Map<String, Object> whereSchool=new HashMap<String, Object>();
//			whereSchool.put("schoolCode", sdCode);
//			getBaseDao().deleteWithoutFullObject(SchoolDetails.class, whereSchool);
//			ComposerException d = new ComposerException(e.getErrorMsg(), e);
//			throw d;
//		} catch (Exception e) {
//			System.out.println("Entering Exception");
//			logger.error(e + e.getMessage() + ":" + e.getCause());
//			Map<String, Object> where=new HashMap<String, Object>();
//			where.put("aaCode", aaCode);
//			getBaseDao().deleteWithoutFullObject(AccessAuthorization.class, where);
//			getBaseDao().deleteWithoutFullObject(AdminDetails.class, where);
//			Map<String, Object> whereSchool=new HashMap<String, Object>();
//			whereSchool.put("schoolCode", sdCode);
//			getBaseDao().deleteWithoutFullObject(SchoolDetails.class, whereSchool);
//			ComposerException d = new ComposerException(e.getMessage(), e);
//			throw d;
//		}
//		logger.info("exiting updateMasterSection");
//		return CommonConstants.SUCCESS;
//	}
//
//
}
